{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "0e1cf3ea",
   "metadata": {},
   "source": [
    "# 一个关于独热编码的Jupyter Notebook\n",
    "本Notebook将演示如何使用Pandas对数据进行独热编码。"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2adff674",
   "metadata": {},
   "source": [
    "## 导入必要的库\n",
    "导入Pandas和其他必要的库。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1630f774",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 导入必要的库\n",
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d60c1b58",
   "metadata": {},
   "source": [
    "## 加载数据\n",
    "使用Pandas加载CSV文件中的数据。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1c2e1f94",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 加载数据\n",
    "data = pd.read_csv('../data/sample.csv')  # 请根据实际路径调整"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "464684e3",
   "metadata": {},
   "source": [
    "## 查看数据\n",
    "打印数据的前几行，并查看需要进行独热编码的列。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "38fb3a72",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 查看数据\n",
    "print(data.head())\n",
    "print(data.columns.tolist())"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3f690823",
   "metadata": {},
   "source": [
    "## 执行独热编码\n",
    "使用Pandas的get_dummies方法对指定列进行独热编码。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "42ce5c11",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 执行独热编码\n",
    "encoded_data = pd.get_dummies(data, columns=['column_to_encode'])  # 替换为实际列名"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "23bf1ab3",
   "metadata": {},
   "source": [
    "## 验证编码结果\n",
    "检查编码后的数据，确保独热编码正确应用。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9654b3cb",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 验证编码结果\n",
    "print(encoded_data.head())"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "pytorch",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "name": "python",
   "version": "3.7.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
